﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/
using System;
using System.Text;
using System.Globalization;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// Image Area Chart Style Class
    /// </summary>
    public class ImageAreaChartStyle : BaseChartStyle
    {
        private readonly string[] _backgroundcolorExclusion = { "#ffffff", "#fff","white" };

        /// <summary>
        /// Gets or sets the color of the background.
        /// The background color for the chart in the Chart API color format.
        /// </summary>
        /// <value>The color of the background.</value>
        public string BackgroundColor {get; set;}

        /// <summary>
        /// Gets or sets a value indicating whether [enable events].
        /// Causes charts to throw user-triggered events such as click or mouse over. Supported only for specific chart types.
        /// </summary>
        /// <value><c>true</c> if [enable events]; otherwise, <c>false</c>.</value>
        public bool EnableEvents { get; set; }

        /// <summary>
        /// Gets or sets the min.
        /// The maximal value to show in the Y axis.
        /// </summary>
        /// <value>The min.</value>
        public float Min { get; set; }

        /// <summary>
        /// Gets or sets the max.
        /// The minimal value to show in the Y axis.
        /// </summary>
        /// <value>The max.</value>
        public float Max { get; set; }

        /// <summary>
        /// Gets or sets the legend.
        /// Position and type of legend. Can be one of the following:
        /// 'right' - To the right of the chart.
        /// 'left' - To the left of the chart.
        /// 'top' - Above the chart.
        /// 'bottom' - Below the chart.
        /// 'none' - No legend is displayed.
        /// </summary>
        /// <value>The legend.</value>
        public LegendPosition Legend { get; set; }


        /// <summary>
        /// Gets or sets a value indicating whether [show category labels].
        /// If set to false, removes the labels of the categories (the X axis labels).
        /// </summary>
        /// <value><c>true</c> if [show category labels]; otherwise, <c>false</c>.</value>
        public bool ShowCategoryLabels { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [show value labels].
        /// If set to false, removes the labels of the values (the Y axis labels).
        /// </summary>
        /// <value><c>true</c> if [show value labels]; otherwise, <c>false</c>.</value>
        public bool ShowValueLabels { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// Text to display above the chart.
        /// </summary>
        /// <value>The title.</value>
        public String Title { get; set; }

        /// <summary>
        /// Gets or sets the value labels interval.
        /// The interval at which to show value axis labels. For example, if min is 0, max is 100, and valueLabelsInterval is 20, the chart will show axis labels at (0, 20, 40, 60, 80 100).
        /// </summary>
        /// <value>The value labels interval.</value>
        public UInt32 ValueLabelsInterval { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ImageAreaChartStyle"/> class.
        /// </summary>
        public ImageAreaChartStyle()
            : base()
        {
            Min = float.MinValue;
            Max = float.MaxValue;
            ShowCategoryLabels = true;
            ShowValueLabels = true;
            ValueLabelsInterval = UInt32.MinValue;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            string baseParams = base.ToString();
            if (!String.IsNullOrWhiteSpace(baseParams))
                sb.Append(baseParams).Append(",");


            if ((!String.IsNullOrWhiteSpace(BackgroundColor)) && (Array.IndexOf(_backgroundcolorExclusion, BackgroundColor.ToLower()) < 0))
                sb.Append("backgroundColor: '").Append(SecureString(BackgroundColor)).Append("',");

            if (EnableEvents)
                sb.Append("enableEvents: true,");

            if ((Legend != LegendPosition.Undefined) && (Legend != LegendPosition.Right))
                sb.Append("legend: '").Append(Legend.ToString(CultureInfo.InvariantCulture).ToLower()).Append("',");

            if (Min > float.MinValue)
                sb.Append("min: ").Append(SecureFloat(Min)).Append(",");

            if (Max > float.MaxValue)
                sb.Append("max: ").Append(SecureFloat(Max)).Append(",");

            if (!ShowCategoryLabels)
                sb.Append("showCategoryLabels: false,");

            if (!ShowValueLabels)
                sb.Append("showValueLabels: false,");

            if (!String.IsNullOrWhiteSpace(Title))
                sb.Append("title: '").Append(SecureString(Title)).Append("',");

            if ((ValueLabelsInterval != UInt32.MinValue) && (ValueLabelsInterval > 0))
                sb.Append("valueLabelsInterval: ").Append(ValueLabelsInterval).Append(",");

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
    }

}
